package com.xzx.shop_front_api.service.impl;

import com.xzx.shop_front_api.entity.exam.User;
import com.xzx.shop_front_api.entity.exam.UserDetails;
import com.xzx.shop_front_api.mapper.exam.UserDetailsMapper;
import com.xzx.shop_front_api.mapper.exam.UserMapper;
import com.xzx.shop_front_api.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserDetails userDetails;
    @Autowired
    private UserDetailsMapper userDetailsMapper;

    @Override
    @Transactional(rollbackFor = RuntimeException.class)

    public int register(User user, UserDetails userDetails) {
        try {
            userMapper.insert(user);
            userDetails.setUserId(user.getId());
            userDetailsMapper.insert(userDetails);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

        return Math.toIntExact(user.getId());
    }
}
